﻿using AutoMapper;
using DncLite.Application.Interfaces;
using DncLite.Application.ViewModels.Student;
using DncLite.Domain.Commands.Student;
using DncLite.Domain.Core.Bus;
using DncLite.Domain.Interfaces;
using System;
using System.Collections.Generic;

namespace DncLite.Application.Services
{
    public class StudentAppService : IStudentAppService
    {
        private readonly IStudentRepository _studentRepository;
        private readonly IMapper _mapper;
        private readonly IMediatorHandler _bus;
        public StudentAppService(IStudentRepository studentRepository
            , IMapper mapper
            , IMediatorHandler bus)
        {
            _studentRepository = studentRepository;
            _mapper = mapper;
            _bus = bus;
        }

        public void Dispose()
        {
            GC.SuppressFinalize(this);
        }

        public IEnumerable<StudentViewModel> GetAll()
        {
            return _mapper.Map<IEnumerable<StudentViewModel>>(_studentRepository.GetAll());
        }

        public StudentViewModel GetById(Guid id)
        {
            return _mapper.Map<StudentViewModel>(_studentRepository.GetById(id));
        }

        public void Register(StudentViewModel studentViewModel)
        {
            var registerStudentCommand = _mapper.Map<RegisterStudentCommand>(studentViewModel);
            _bus.SendCommand(registerStudentCommand);
        }

        public void Remove(Guid id)
        {
            throw new NotImplementedException();
        }

        public void Update(StudentViewModel studentViewModel)
        {
            throw new NotImplementedException();
        }
    }
}
